<?php

namespace common\Table\InputClick;

use common\Table\baseTable;

class AdClickShikeTable extends baseTable {

    private $_table = 'ad_click_shike_';

    public function insertAdShikeClick($adClickColumns, $tableNum) {
        return $this->db->insert($adClickColumns, $this->_table . $tableNum);
    }
    
    public function selectByIdfa($appid, $idfa, $eventTimestamp, $maxSecond, $tableNum) {
        return $this->db->selectOne('select id, input_timestamp from ' . $this->_table . $tableNum . ' where (select input_timestamp from '. $this->_table . $tableNum .' where idfa=:idfa and appid = :appid) + '. $maxSecond .' >= :eventTimestamp and idfa = :idfa and appid = :appid', array('eventTimestamp' => $eventTimestamp, 'idfa' => $idfa, 'appid' => $appid));
    }
    
    public function selectIdByAppidAndIdfa($appid, $idfa, $tableNum) {
        return $this->db->selectOne('select id, callback from ' . $this->_table . $tableNum . ' where idfa=:idfa and appid=:appid order by input_timestamp desc', array('idfa' => $idfa, 'appid' => $appid));
    }
}
